
let vertex2string =
	fun p scale -> ("v "^(string_of_float (p.Geometry.x*.scale))^" "
		     ^(string_of_float (p.Geometry.z))^" "
		     ^(string_of_float (p.Geometry.y*.scale)))

let face2string =
	fun index -> ("f "^(string_of_int (index*3 + 1))
			 ^" "^(string_of_int (index*3 + 2))
			 ^" "^(string_of_int (index*3 + 3)))
let face2stringi a b c=
     ("f "^(string_of_int (a))
     ^" "^(string_of_int (b))
     ^" "^(string_of_int (c)))

let openObj fileName =
	open_out (fileName)

let closeObj outchannel =
	close_out outchannel

let write_triangle c t index scale=
	begin
		Printf.fprintf c "%s\n" (vertex2string t.Geometry.sa scale);
		Printf.fprintf c "%s\n" (vertex2string t.Geometry.sb scale);
		Printf.fprintf c "%s\n" (vertex2string t.Geometry.sc scale);
		Printf.fprintf c "%s\n" (face2string index);
	end

let write_point c  pt scale=
   Printf.fprintf c "%s\n" (vertex2string pt scale)

let write_face c t =
   Printf.fprintf c "%s\n" (face2stringi (t.Geometry.isa+1)
                                         (t.Geometry.isb+1)
                                         (t.Geometry.isc+1))

